<!-- 公共头部  --> 
<template>
  <section>
    <div class="com_head" :class="$route.name=='index'?'curr':''">
      <div class="w1320 clearfix">
        <router-link to="/index" class="logo fl">
          <img src="../assets/image/logo@2x.png" alt="logo">
        </router-link>
        <ul class="head_list clearfix fl">
          <router-link to="/index" tag="li">首页</router-link>
          <router-link to="/trade" tag="li">交易</router-link>
          <template v-if="token">
            <li
              :class="($route.matched&&$route.matched[0]&&$route.matched[0].name=='order')?'router-link-active':''"
            >
              <span @click="$router.push('/order/position')">订单</span>
              <ul class="hid order_hid">
                <router-link to="/order/position" tag="li">当前持仓</router-link>
                <router-link to="/order/pending" tag="li">挂单记录</router-link>
                <router-link to="/order/history" tag="li">历史记录</router-link>
              </ul>
            </li>
            <router-link to="/assets/usdt" tag="li" :class="zcSelect?'router-link-active':''">资产</router-link>
          </template>
          <router-link to="/stock" tag="li">股票行情</router-link>
          <li v-if="token" :class="mySelect?'router-link-active':''">
            我的
            <div class="hid my_hid" v-if="user">
              <div class="user_info">
                <div class="fl">
                  <p class="txt">{{$js.phoneMd(user.mobile)}}</p>

                  <span class="money">可用资金:{{dataShow.usable}}</span>
                </div>
                <dir class="fr">
                  <img v-if="user.is_head_img==1" :src="user.head_img">
                  <img src="../assets/image/pic_morentouxiang@2x.png" v-else>
                </dir>
              </div>
              <ul>
                <router-link class="first" to="/safety" tag="li">账户安全</router-link>
                <router-link to="/announcement" tag="li">平台公告</router-link>
                <router-link to="/invite" tag="li">
                  邀请好友
                  <span>热门</span>
                </router-link>
                <router-link to="/newPlayer" tag="li">新手指引</router-link>
                <li @click="outLogin">退出登录</li>
              </ul>
            </div>
          </li>
        </ul>
        <div class="service fr">
          <p>
            <img src="../assets/image/kefu.png" alt width="22">
            咨询客服
          </p>
          <div class="hid">
            <img :src="conf.service_img" alt>
            <p>添加客服微信</p>
          </div>
        </div>
        <div class="head_btns fr" v-if="!token">
          <button @click="alterChoose(2)" class="head_btn">登录</button>
          <button class="curr head_btn" @click="alterChoose(1)">注册</button>
        </div>
      </div>
      <base-alert :bol.sync="alertBol" :type.sync="alertType" title="忘记"></base-alert>
    </div>
  </section>
</template>

<script>
import { _loginOut } from "@/axios/index.js";
export default {
  data() {
    return {
      registerBol: true, // 注册弹窗
      alertBol: false, // 弹窗
      alertType: 1 //弹窗类型
    };
  },
  created() {},
  props: {},
  computed: {
    conf() {
      return this.$store.state.confObj;
    },
    mySelect() {
      var name = this.$route.name;
      return (
        name == "safety" ||
        name == "announcement" ||
        name == "invite" ||
        name == "newPlayer"
      );
    },
    zcSelect() {
      var name = this.$route.name;
      return (
        name == "recharge" ||
        name == "rechargeRecords" ||
        name == "withdraw" ||
        name == "withdrawRecords"
      );
    },
    //数据展示集合
    dataShow() {
      return this.$js.userAssetNews();
    },
    user() {
      return this.$store.state.user;
    },
    token() {
      return this.$store.state.token;
    }
  },

  watch: {
    $route() {},
    user() {
      if (this.user) this.$store.getters.countCcDataList;
    }
  },
  methods: {
    alterChoose(type) {
      this.alertType = type;
      this.alertBol = true;
    },
    async outLogin() {
      var _self = this;
      const res = await _loginOut({ token: localStorage.getItem("token") });
      if (res.data.code == 200) {
        _self.logout();
      } else {
        _self.$Message.error("退出失败,请重试");
      }
    },
    logout() {
      if (location.hash == "#/trade" || location.hash == "#/stock") {
        this.$store.commit("cleartloding");
      } else {
        this.$store.commit("cleartloding", "/index");
      }
      this.$Message.success({
        content: "退出成功"
      });
    }
  },

  mounted() {}
};
</script>